package com.wxxymaker.edu.init;

import com.blade.Blade;
import com.blade.Environment;
import com.blade.ioc.annotation.Bean;
import com.blade.loader.BladeLoader;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import io.github.biezhi.anima.Anima;
import io.github.biezhi.ome.OhMyEmail;

import java.util.Map;
import java.util.Properties;

import static io.github.biezhi.ome.OhMyEmail.SMTP_QQ;

/**
 * @Author: soft
 * @Date: 2018/7/23 20:45
 * @Desc: 数据库初始化
 */
@Bean
public class DaoBean implements BladeLoader {

    @Override
    public void load(Blade blade) {
        Environment ev = blade.environment();
        Map<String, Object> hikari = ev.getPrefix("hikari");
        Properties ps = new Properties();
        ps.putAll(hikari);

        HikariDataSource dataSource = new HikariDataSource(new HikariConfig(ps));
        Anima.open(dataSource);

        Map<String, Object> prefix = ev.getPrefix("email");
        String account = (String) prefix.get("account");
        String password = (String) prefix.get("password");
        OhMyEmail.config(SMTP_QQ(false), account, password);
    }
}
